package com.snow.springboot.controller;

import com.alibaba.fastjson.JSONObject;
import com.snow.springboot.entity.NcmsInfo;
import com.snow.springboot.service.DiagnoseService;
import com.snow.springboot.service.NcmsService;
import com.snow.springboot.util.MultiTaskPool;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

/**
 * @Package: com.snow.springboot.controller
 * @ClassName: NcmsController
 * @Description:
 * @author: lurui
 * @Date: 2018/10/24 下午3:54
 * @version:
 */
@Controller
@RequestMapping("/ncms")
public class NcmsController {
    private static final Logger LOGGER = LoggerFactory.getLogger(NcmsController.class);
    @Autowired
    private NcmsService ncmsService;
    @Value("${ncmspath}")
    private String filePath;
    @Autowired
    private DiagnoseService diagnoseService;

    @GetMapping(value = "/add")
    @ResponseBody
    public JSONObject addNcmsInfo() {
        BlockingQueue<NcmsInfo> queue = new LinkedBlockingQueue<NcmsInfo>(50);
        MultiTaskPool multiTaskPool = MultiTaskPool.getInstance();
        this.ncmsService.productNcmsService(filePath, queue, multiTaskPool);
        this.ncmsService.consumeNcmsInfo(queue, 10, multiTaskPool);
        JSONObject result = new JSONObject();
        result.put("result", "OK");
        return result;
    }

}
